package main

import (
	"net/http"
	"text/template"

	"gitee.com/shuwenhe/shuwen-mall/controller"
)

func main() {
	// 处理静态资源 css html
	http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("views/static"))))
	http.Handle("/pages/", http.StripPrefix("/pages/", http.FileServer(http.Dir("views/pages"))))
	http.HandleFunc("/", IndexHandler)
	http.HandleFunc("/login", controller.Login)
	http.HandleFunc("/regist", controller.Regist)
	http.HandleFunc("/getItems", controller.GetItems)
	http.HandleFunc("/addItems", controller.AddItems)
	http.HandleFunc("/deleteItem", controller.DeleteItem)
	http.HandleFunc("/getItemByID", controller.GetItemByID)
	http.HandleFunc("/updateItem", controller.UpdateItem)

	http.ListenAndServe(":8080", nil)
}

func IndexHandler(w http.ResponseWriter, r *http.Request) {
	// 模板解析
	t := template.Must(template.ParseFiles("views/index.html"))
	// 执行
	t.Execute(w, "")
}
